﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace EasyTest {

    /// <summary>
    /// Text object
    /// </summary>
    public class Text {

        /// <summary>
        /// String representing the Document Element to be searched for.
        /// </summary>
        private string FindBy { get; set; }

        /// <summary>
        /// Container in which to search for this Text element.
        /// </summary>
        private Focus Focus { get; set; }

        /// <summary>
        /// Create a new Text object.
        /// </summary>
        /// <param name="findBy">HTML text to identify and find elements within a document.</param>
        public Text(string findBy) {
            FindBy = findBy;
            Focus = new Focus();
        }
        public bool IsDisplayed()
        {
            Focus.Go();
            return Action.IsDisplayed(FindBy);
        }
        /// <summary>
        /// Create a new Text object.
        /// </summary>
        /// <param name="findBy">HTML text to identify and find elements within a document.</param>
        /// <param name="focus">Document container with controls to search for.</param>
        public Text(string findBy, Focus focus)
            : this(findBy) {
            Focus = focus;
        }

        /// <summary>
        /// Verify that the Text property is set to the text string passed.
        /// </summary>
        /// <param name="textToVerify">Text to search for in the .Text property of the Document Element found.</param>
        public void VerifyTextEquals(string textToVerify) {
            Focus.Go();
            Action.VerifyText(FindBy, textToVerify);
        }

        /// <summary>
        /// Verify that the Text property is set to the text string passed.
        /// </summary>
        /// <param name="textToVerify">Text to search for in the .Text property of the Document Element found.</param>
        /// <param name="errorMessage">Error message to be displayed if there is no match.</param>
        public void VerifyTextEquals(string textToVerify, string errorMessage) {
            Focus.Go();
            Action.VerifyText(FindBy, textToVerify, errorMessage);
        }

        /// <summary>
        /// Verify that the Text property is contains the text string passed.
        /// </summary>
        /// <param name="textToVerify">Text to search for in the .Text property of the Document Element found.</param>
        public void VerifyTextContains(string textToVerify) {
            Focus.Go();
            Action.VerifyContainsText(FindBy, textToVerify, "");
        }

        /// <summary>
        /// Verify that the Text property is contains the text string passed.
        /// </summary>
        /// <param name="textToVerify">Text to search for in the .Text property of the Document Element found.</param>
        /// <param name="errorMessage">Error message to be displayed if there is no match.</param>
        public void VerifyTextContains(string textToVerify, string errorMessage) {
            Focus.Go();
            Action.VerifyContainsText(FindBy, textToVerify, errorMessage);
        }
        public string GetText()
        {
            Focus.Go();
            return Action.GetText(FindBy);
        }
    }
}
